from django.db import connection

def articles_of_user(user_id):
    # ---- 用户文章 -----
    articles_of_author_sql="select article.*,user.name name from article,user where user.id=%s and article.user_id=user.id order by created_date"%(
        str(user_id))

    with connection.cursor() as cursor:
        cursor.execute(articles_of_author_sql)
        articles=[]
        append=articles.append
        if cursor.rowcount!=0:
            for row in cursor.fetchall():
                append(dict(zip([desc[0] for desc in cursor.description],row)))

    # ---- 原创文章梳理和阅读总数----
    read_num_total=0
    original_article_num=0
    for article in articles:
        if article["is_original"]==1:
            original_article_num+=1
        read_num_total+=article["read_num"]

    return {"articles":articles,"read_num_total":read_num_total,"original_article_num":original_article_num}
